package com.dayuanit.dy15.ebook.bookshop.controller;

import com.dayuanit.dy15.ebook.bookshop.redis.RedisService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Controller
public class ViewController {

    @Resource(name = "redisServiceTempleImpl")
    private RedisService redisService;

    @RequestMapping(value = {"/", "/index"})
    public String toIndex() {
        return "index";
    }

    @RequestMapping(value = "/books/{firstNavId}/{secondNavId}/{thirdNavId}")
    public String thirdNavBooks(@PathVariable("firstNavId") String firstNavId,
                                @PathVariable("secondNavId") String secondNavId,
                                @PathVariable("thirdNavId") String thirdNavId, HttpServletRequest request) {
        request.setAttribute("firstNavId", firstNavId);
        request.setAttribute("secondNavId", secondNavId);
        request.setAttribute("thirdNavId", thirdNavId);
        System.out.println("thirdNavId=" + thirdNavId);
        return "third";
    }


    @RequestMapping(value = "/book/{bookId}.html")
    public String bookDetail(@PathVariable("bookId") long bookId, HttpServletRequest request) {
        request.setAttribute("bookId", bookId);

        redisService.addHomeBook(1, String.valueOf(bookId));
        return "bookDetail";
    }

    @RequestMapping(value = "/card/toCard.html")
    public String toCard() {
        return "card";
    }

    @RequestMapping(value = "/card/toSettlement.html")
    public String toSettlement() {
        return "settlement";
    }

}
